package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.Surveycontent;

public class SurveyContentDao extends BaseSql<Surveycontent> {
	private Connection conn;

	public SurveyContentDao() {
		conn = DBUtile.getConnection();
	}

	public List<Surveycontent> getItemContent(Integer id) {
		List<Surveycontent> list = new ArrayList<>();
		String sql = "select * from courses where id in(select course_id from majorcourse where major_id in(select id from surveyitems where id=?))";
		try {
			PreparedStatement pstm = conn.prepareStatement(sql);
			pstm.setInt(1, id);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				Surveycontent sc = new Surveycontent();
				sc.setId(rs.getInt("id"));
				sc.setContent(rs.getString("content"));
				list.add(sc);
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}

	}
}
